Density contours
Contents
3. Density contours¶
3.1. 概要¶
3.2. Plotlyによる作図方法¶
3.3. MADB Labを用いた作図例¶
3.3.1. 下準備¶
import pandas as pd
import plotly.express as px
import warnings
warnings.filterwarnings('ignore')
# 前処理の結果,以下に分析対象ファイルが格納されていることを想定
PATH_DATA = '../../data/preprocess/out/episodes.csv'
# Jupyter Book用のPlotlyのrenderer
RENDERER = 'plotly_mimetype+notebook'
# 連載週数の最小値
MIN_WEEKS = 5
def show_fig(fig):
"""Jupyter Bookでも表示可能なようRendererを指定"""
fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
fig.show(renderer=RENDERER)
df = pd.read_csv(PATH_DATA)
3.3.2. 作品別の平均掲載位置と連載週数¶
df_plot = \
df.groupby('cname')['pageStartPosition'].\
agg(['count', 'mean']).reset_index()
df_plot.columns = ['cname', 'weeks', 'position']
df_plot = \
df_plot[df_plot['weeks'] >= MIN_WEEKS].reset_index(drop=True)
fig = px.density_contour(
df_plot, x='position', y='weeks',)
show_fig(fig)
fig.update_yaxes(range=[0, 200])
show_fig(fig)
fig.update_traces(
contours_coloring="fill",
contours_showlabels = True)
show_fig(fig)
3.3.3. 雑誌別・作品別の平均掲載位置と連載週数¶
df_plot = \
df.groupby(['mcname', 'cname'])['pageStartPosition'].\
agg(['count', 'mean']).reset_index()
df_plot.columns = ['mcname', 'cname', 'weeks', 'position']
df_plot = \
df_plot[df_plot['weeks'] >= MIN_WEEKS].reset_index(drop=True)
fig = px.density_contour(
df_plot, x='position', y='weeks',
color='mcname')
fig.update_yaxes(range=[0, 200])
show_fig(fig)